from logger import logger
from sub_events.base_event import BaseEvent

LOGGER = logger.CustomLogger()

class AllReviewEvent(BaseEvent):
    def __init__(self, **kwargs):
        super().__init__(**kwargs)
        self.event_name_zh: str = "全体加分"
        self.event_name_en: str = "All-Group Review"

    def pre_execute(self) -> bool:
        return self.hook.commenter == 'https://gitee.com/sunfei2021'

    def execute(self) :
        """
        斐哥一声令下，所有组都给你加分！
        """
        for group in self.cfg.get("accounts", {}).get("groups"):
            access_token = self.cfg.get("accounts", {}).get("groups")[group]
            headers = {'Authorization': f'token {access_token}'}
            response = self.git_client.review(self.hook.pr_number, headers=headers)
            LOGGER.info(f"[{self.hook.pr_number}] sunfei pass all to the pr, response code {response.status_code}")
        return False
